<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首付款信息详情</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
.sq-formTable .field {
		width: 150px;
	}
</style>
</head>
<body class="iframeBody">
	<form id="fncPrjFstpyInfo_detail_form">
		<div class="fieldset1 tabel_col tabel_col_s clearFix ">
		
			<div class="caption">
				<span class="title">基本信息 </span>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">项目名称：</div>
				<div class="field">
					<span name="fncPrjNm" id="fncPrjNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">项目编号：</div>
				<div class="field">
					<span name="fncPrjIdStr" id="fncPrjIdStr"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">创建时间：</div>
				<div class="field">
					<span name="crtTm" id="crtTm"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">融资机构：</div>
				<div class="field">
					<span name="fundRasInsNm" id="fundRasInsNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资报价：</div>
				<div class="field">
					<a id="showScmDetail" href=""><span name="fncScmNm" id="fncScmNm" style="color:blue;text-decoration:underline"></span></a>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资基数：</div>
				<div class="field">
					<span name="fncCrdnltNm" id="fncCrdnltNm"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">打折率：</div>
				<div class="field">
					<span name="dcnRate" id="dcnRate"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">计划融资起始日期：</div>
				<div class="field">
					<span name="stdt" id="stdt"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">计划融资终止日期：</div>
				<div class="field">
					<span name="eddt" id="eddt"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">授信合同号：</div>
				<div class="field">
					<span name="crCtrNo" id="crCtrNo"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">授信名称：</div>
				<div class="field">
					<span name="crNm" id="crNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">授信余额：</div>
				<div class="field">
					<span name="crBal" id="crBal"></span>
				</div>
			</div>
			
			
			<div class="fieldBox col_33">
				<div class="label">项目金额：</div>
				<div class="field">
					<span name="fncPrjAmt" id="fncPrjAmt"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资金额：</div>
				<div class="field">
					<span name="fncFiAmt" id="fncFiAmt"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">支付表数量：</div>
				<div class="field">
					<span name="payCnt" id="payCnt"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">产品名称：</div>
				<div class="field">
					<span name="pdNm" id="pdNm"></span>
				</div>
			</div>
			
			<div id="bankDiv">
				<div class="caption">
					<span class="title">付款信息 </span>
				</div>
			
				<div class="fieldBox col_33">
					<div class="label">实际融资金额：</div>
					<div class="field">
						<span name="acFiAmt" id="acFiAmt"></span>
						<span style="color:red">（是否坐扣：<span name="wthrDdctFstPay" id="wthrDdctFstPay"></span>）</span>
					</div>
				</div>
				
				
			</div>
			
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					<input name="dataId" id="dataId" type="text" class="ui-textbox" value="${fncPrjId}">
				</div>
			</div>
			
		</div>
		
		<div class="fieldset1 tabel_col tabel_col_s clearFix " id="fstpyDiv">
			<div class="caption">
				<span class="title">付款明细 </span>
			</div>
			<div class="fieldBox"></div>
			<div style="width:1100px; overflow:auto;">
			<!-- <table id="fstpyTable" class="sq-formTable" style="width:100%">
				<tbody>
					<tr>
						<td style="padding: 0;text-align: center;"> -->
							<table id="tableMain" class="sq-formTable no-border" >
								<thead>
									<tr>
										<th class="tbLabel" style="text-align: center;" >费用名称</th>
										<th class="tbLabel" style="text-align: center; ">费用比例（%）</th>
										<th class="tbLabel" style="text-align: center;">是否坐扣</th>
										<th class="tbLabel" style="text-align: center;">费用金额</th>
										<th class="tbLabel" style="text-align: center;">已付金额</th>
										<!-- <th class="tbLabel" style="text-align: center;">保证金是否已付</th> -->
										<th class="tbLabel" style="text-align: center;">关联保证金的项目</th>
										<th class="tbLabel" style="text-align: center;">退回时间</th>
										<th class="tbLabel" style="text-align: center;">机构收款账户</th>
										<!-- <th class="tbLabel" style="text-align: center;">收款单位</th>
										<th class="tbLabel" style="text-align: center;">收款开户行号</th>
										<th class="tbLabel" style="text-align: center;">收款开户行名</th> -->
										<th class="tbLabel" style="text-align: center;">我司付款账户</th>
										<th class="tbLabel" style="text-align: center;">我司账户名称</th>
										<th class="tbLabel" style="text-align: center;">付款时间</th>
										<th class="tbLabel" style="text-align: center;">备注</th>
									</tr>
								</thead>
								<tbody>
									<tr id="totalTr">
										<td style="text-align: right;" colspan="3">合计：</td>
										<td style="text-align: center;"><span name="totalCost" ></span></td>
										<td style="text-align: center;" ><span name="totalPay" ></span></td>
										<td style="text-align: center;" colspan="2"></td>
									</tr>
								</tbody>
							</table>
						</td>
					<!-- </tr>
				</tbody>
			</table> -->
			</div>
		</div>
	</form>
	<script>
		$(function() {
		   $("#fncPrjFstpyInfo_detail_form").ligerForm({
                validate: true
           });
	       initData();
		});
		
		function initData(){
			var dataId = $("#dataId").val();
	    	if(!dataId)return;
	    	var _url = '<%=path%>/rfbase/fncprjfstpyinfo/getById.do';
	    	var wthrDdctFstPay = '0,2'; // 不坐扣的数据
	    	AjaxUtils.ajaxPost(_url, {
				fncPrjId : dataId,
				wthrDdctFstPay : wthrDdctFstPay
			},  callback);
    	}
		
		//新增回调
		function callback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
				 setAccDetail(); //点击链接，显示机构或我司帐户详情
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//设置页面数据
	    function setData(data){
			var h = "javascript:showScmDetail("+data.fncScmId+")";
			$("#showScmDetail").attr("href",h);
			
	    	$("#fncPrjIdStr").html(data.fncPrjIdStr);
	    	$("#fncPrjNm").html(data.fncPrjNm);
	    	$("#crtTm").html(renderDate(data.crtTm));
	    	$("#fundRasInsNm").html(data.fundRasInsNm);
	    	$("#fncScmNm").html(data.fncScmNm);
	    	$("#fncCrdnltNm").html(data.fncCrdnltNm);
	    	$("#dcnRate").html(accMul(data.dcnRate,100)+"%");
	    	$("#stdt").html(renderDate(data.stdt));
	    	$("#eddt").html(renderDate(data.eddt));
	    	$("#crNm").html(data.crNm);
	    	$("#pdNm").html(data.pdNm);
	    	$("#crCtrNo").html(data.crCtrNo);
	    	$("#crBal").html(commafy(data.crBal));
	    	$("#payCnt").html(data.payCnt);
	    	
	    	$("#fncPrjAmt").html(commafy(data.fncPrjAmt));
	    	$("#fncFiAmt").html(commafy(data.fncFiAmt));
	    	$("#wthrDdctFstPay").html(renderYesNo(data.wthrDdctFstPay));
	    	$("#acFiAmt").html(commafy(data.acFiAmt));
	    	var payBank = data.bkAccInfoVO;
	    	if(null != payBank){
	    		$("#fstpyPayAccno").html(payBank.accNo);
	    	}
	    	var recvBank = data.baccInfoVO;
	    	if(null != recvBank){
	    		$("#recvAccNum").html(recvBank.accNum);
		    	$("#recvAccNm").html(recvBank.accNm);
		    	$("#recvBanAccNum").html(recvBank.banAccNum);
		    	$("#recvBanAccNm").html(recvBank.banAccNm);
	    	}
	    	
	    	var totalPayAmt = 0;
			var totalCostAmt = 0;
			//首付款信息
			var fstpyVos = data.fncPrjFstpyInfoVOs;
			for (var i = 0; i < fstpyVos.length; i++) {
				addRow(fstpyVos[i]);
				var tr = $('#tableMain tbody tr:eq('+i+')');
				if(fstpyVos[i].costPct== '' || null ==fstpyVos[i].costPct || fstpyVos[i].costPct == 0){
					fstpyVos[i].costPct = '--';
				}else{
					/* 百分比显示 */
					fstpyVos[i].costPct = accMul(fstpyVos[i].costPct,100);
				}
				tr.find("span[name='costNm']").html(fstpyVos[i].costNm);
				tr.find("span[name='costPct']").html(fstpyVos[i].costPct);
				tr.find("span[name='wthrDdct']").html(renderYesNo(fstpyVos[i].wthrDdct,fstpyVos[i].mrgnIs));
				tr.find("span[name='costAmt']").html(commafy(fstpyVos[i].costAmt));
				tr.find("span[name='payAmt']").html(commafy(fstpyVos[i].payAmt));
				/* if(fstpyVos[i].isAlreadyPay =="yes") {
					tr.find("span[name='isAlreadyPay']").html("是");	
				}else if(fstpyVos[i].isAlreadyPay =="no") {
					tr.find("span[name='isAlreadyPay']").html("否");
				}  */
				
				if(fstpyVos[i].fncPrjBscInfoVO) {
					tr.find("span[name='whichPrjId']").html(fstpyVos[i].fncPrjBscInfoVO.fncprjnm);	
				}
				tr.find("span[name='reReturnTm']").html(renderDate(fstpyVos[i].reReturnTm));	
				
				if(fstpyVos[i].bankAccInfoVO) {
					tr.find("span[name='recAccount']").html(fstpyVos[i].bankAccInfoVO.accNum);//机构收款账户
				/* 	tr.find("span[name='accNm']").html(fstpyVos[i].bankAccInfoVO.accNm);//收款单位
					tr.find("span[name='banAccNum']").html(fstpyVos[i].bankAccInfoVO.banAccNum);//收款开户行号
					tr.find("span[name='banAccNm']").html(fstpyVos[i].bankAccInfoVO.banAccNm);//收款开户行名 */
				}
				if(fstpyVos[i].sysBkAccInfoVO) {
					tr.find("span[name='payAccount']").html(fstpyVos[i].sysBkAccInfoVO	.accNo);//我司付款账户
					tr.find("span[name='payAccountNm']").html(fstpyVos[i].sysBkAccInfoVO.accNm);//我司账户名称
				}
				
				tr.find("span[name='fstpyTm']").html(renderDate(data.fstpyTm));
				tr.find("span[name='rmrk']").html(fstpyVos[i].rmrk);
				totalCostAmt += fstpyVos[i].costAmt;
				totalPayAmt += fstpyVos[i].payAmt;
			}
			
			$('#totalTr').find("span[name='totalCost']").html(commafy(totalCostAmt));
			$('#totalTr').find("span[name='totalPay']").html(commafy(totalPayAmt));
			
			 isWthrDdct(data.wthrDdctFstPay);
	    
		};
		
		//查看融资报价
		function showScmDetail(_id){
			if(!_id)return;
			Add_navTab('PrdSpl_1'+_id,'查看融资报价','<%=path%>/rfbase/scmbaseinfo/toDetail.do?id='+_id);
		}
		
		 //格式化时间
		 function renderDate(value){
			var dateStr = "";
			if(null != value &&  ""!= value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr;
		 }
		 
		function addRow(fstpyVo){
			$('#totalTr').before('<tr>'+
				'<td style="text-align: center;" >'+
					'<div class="field" >'+
						'<span name="costNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costPct" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="wthrDdct" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costAmt" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="payAmt" ></span>'+
					'</div>'+
				'</td>'+
				/* '<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="isAlreadyPay" ></span>'+
					'</div>'+
				'</td>'+ */
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="whichPrjId" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
				'<div class="field">'+
					'<span name="reReturnTm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="recAccount" class="insAccNo" accId="'+(fstpyVo.bankAccInfoVO?fstpyVo.bankAccInfoVO.id:"")+'" ></span> '+
					'</div>'+
				'</td>'+
					/* '<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="accNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="banAccNum" ></span>'+
					'</div>'+
				'</td>'+
			'<td style="text-align: center;">'+
				'<div class="field">'+
					'<span name="banAccNm" ></span>'+
				'</div>'+
			'</td>'+ */
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="payAccount" class="myAccNo" accId="'+(fstpyVo.sysBkAccInfoVO?fstpyVo.sysBkAccInfoVO.id:"")+'"></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
				'<div class="field">'+
					'<span name="payAccountNm" ></span>'+
				'</div>'+
			'</td>'+
			'<td style="text-align: center;">'+
				'<div class="field">'+
					'<span name="fstpyTm" ></span>'+
				'</div>'+
			'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="rmrk" ></span>'+
					'</div>'+
				'</td>'+
			'</tr>');
		}
		
		function isWthrDdct(val){
			if(val == 0 || val == 2){
				$('#bankDiv').show();
				$('#fstpyDiv').show();
			}else{
				$('#bankDiv').hide();
				$('#fstpyDiv').hide();
			}
		}
		
		//显示是否
		function renderYesNo(value,mrgnIs){
			var dateStr = "";
			if(0 == value){
				dateStr = "否";
			}
			if(1 == value){
				dateStr = "是";
			}
			if(2 == value){
				if(mrgnIs==1) {
					dateStr = "默认已付";
				}else {
					dateStr = "是/否";	
				}
			}
			return dateStr;
		}
		
		//数字格式转换成千分位
		 function commafy(s){
		     return formatMoney(s);
		  }
		
		function formatMoney(number, places, symbol, thousand, decimal) {
			number = number || 0;
			places = !isNaN(places = Math.abs(places)) ? places : 2;
			// symbol = symbol !== undefined ? symbol : "$";
			symbol = symbol !== undefined ? symbol : "";
			thousand = thousand || ",";
			decimal = decimal || ".";
			var negative = number < 0 ? "-" : "", 
				i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10)+ "",
				j = (j = i.length) > 3 ? j % 3 : 0;
			return symbol
					+ negative
					+ (j ? i.substr(0, j) + thousand : "")
					+ i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand)
					+ (places ? decimal
					+ Math.abs(number - i).toFixed(places).slice(2) : "");
		}
		
		   //js 加法计算  
		   //调用：accAdd(arg1,arg2)  
		   //返回值：arg1加arg2的精确结果   
		   function accAdd(arg1,arg2){   
		     var r1,r2,m;   
		     try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}   
		     try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}   
		     m=Math.pow(10,Math.max(r1,r2))   
		     //return ((arg1*m+arg2*m)/m).toFixed(2);   
		     return ((arg1*m+arg2*m)/m); 
		   }   
		   //js 减法计算  
		   //调用：Subtr(arg1,arg2)  
		   //返回值：arg1减arg2的精确结果   
		   function Subtr(arg1,arg2){  
		        var r1,r2,m,n;  
		        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}  
		        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}  
		        m=Math.pow(10,Math.max(r1,r2));  
		        //last modify by deeka  
		        //动态控制精度长度  
		        n=(r1>=r2)?r1:r2;  
		        return ((arg1*m-arg2*m)/m).toFixed(2);  
		   }   
		   //js 除法函数  
		   //调用：accDiv(arg1,arg2)  
		   //返回值：arg1除以arg2的精确结果   
		   function accDiv(arg1,arg2){   
		     var t1=0,t2=0,r1,r2;   
		     try{t1=arg1.toString().split(".")[1].length}catch(e){}   
		     try{t2=arg2.toString().split(".")[1].length}catch(e){}   
		     with(Math){   
		       r1=Number(arg1.toString().replace(".",""))   
		       r2=Number(arg2.toString().replace(".",""))   
		       return (r1/r2)*pow(10,t2-t1);   
		     }   
		   }   
		     
		   //js 乘法函数  
		   //调用：accMul(arg1,arg2)   
		   //返回值：arg1乘以arg2的精确结果   
		   function accMul(arg1,arg2)   
		   {   
		     var m=0,s1=arg1.toString(),s2=arg2.toString();   
		     try{m+=s1.split(".")[1].length}catch(e){}   
		     try{m+=s2.split(".")[1].length}catch(e){}   
		     return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)   
		   }  
		   
		   //点击链接，显示机构或我司帐户详情
		   function setAccDetail() {
			   
			    //机构账户详情
				$(".insAccNo").each(function(){
				    
					$(this).css("color","blue");
				    $(this).css("text-decoration","underline");
				    $(this).css("cursor","Pointer");

				    $(this).click(function () {
				    	
				    	var accId = $(this).attr("accId");//机构帐户id
				    	if(accId) {
				    		$.ligerDialog.SQopen({
				                url: '<%=path%>/rfbase/fribaseinfo/insAccNoDetail.do?id='+accId,
				                width: 600,
				                height:250,
				                title : '机构账户信息',
				                buttons: [{
				    	                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-ok',
				    	                onclick: function (item, Dialog) {
				    	                    if (Dialog.onCancel) Dialog.onCancel();
				    	                }
				    	            }
				    	        ]
				    		});
				    	}
					}); 
				});
				
			
				//我司账户详情
				$(".myAccNo").each(function(){
				    
					$(this).css("color","blue");
				    $(this).css("text-decoration","underline");
				    $(this).css("cursor","Pointer");

				    $(this).click(function () {
				    	
				    	var accId = $(this).attr("accId");//我司账户id
				    	if(accId) {
				    		$.ligerDialog.SQopen({
				                url: '<%=path%>/system/sysBkAccInfo/myAccNoDetail.do?id='+accId,
				                width: 600,
				                height:250,
				                title : '我司账户信息',
				                buttons: [{
				    	                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-ok',
				    	                onclick: function (item, Dialog) {
				    	                    if (Dialog.onCancel) Dialog.onCancel();
				    	                }
				    	            }
				    	        ]
				    		});
				    	}
					}); 
				});
				
		   }
		   
	</script>
</body>
</html>